<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="./common/header.jsp"/>
<link rel="stylesheet" type="text/css" href="static/webuploader/webuploader.css">
<script type="text/javascript" src="static/webuploader/webuploader.js"></script>
<body>
<div class="container">
    <%--<div id="uploader" class="wu-example" style="margin-top:30px">--%>
        <%--<!--用来存放文件信息-->--%>
        <%--<div id="thelist" class="uploader-list"></div>--%>
        <%--<div class="btns">--%>
            <%--<div id="picker">上传文件</div>--%>
            <%--&lt;%&ndash;<button id="ctlBtn" class="btn btn-default">开始上传</button>&ndash;%&gt;--%>
        <%--</div>--%>
    <%--</div>--%>
    <div class="btns">
        <div id="toUpload" class="btn btn-default" style="margin:20px 0">上传文件</div>

    </div>
    <table class="table">
        <thead>
        <tr>
            <th>文件名</th>
            <th>文件大小</th>
            <th>修改时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tbody">
        </tbody>
    </table>
</div>
<script type="text/javascript">


    var doSearch = function () {
        $.ajax({
            type: "GET",
            url: "/donwload/files",
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {
                    var list = data.result;
                    var listContent = "";
                    for (var i in list) {
                        listContent += '<tr>';
                        listContent += '<td>' + list[i].fileName + '</td>';
                        listContent += '<td>' + bytesToSize(list[i].fileSize) + '</td>';
                        listContent += '<td>' + timeStamp2String(list[i].createdTime) + '</td>';
                        listContent += '<td><a title="下载" href="/download/file?fileName='  + list[i].fileName + '" class="fs14 btn btn-primary btn-icon circle_plus">下载</a><div class="clear"></td> ';
                        listContent +='</tr>';
                        //产品名称
                    }
                    $("#tbody").html(listContent);

                }
            },
            error: function () {

            }
        });
    }
    $(document).ready(function () {
        doSearch();
    });
    function timeStamp2String (time){
        var datetime = new Date();
        datetime.setTime(time);
        var year = datetime.getFullYear();
        var month = datetime.getMonth() + 1;
        var date = datetime.getDate();
        var hour = datetime.getHours();
        var minute = datetime.getMinutes();
        var second = datetime.getSeconds();
        var mseconds = datetime.getMilliseconds();
        return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second+"."+mseconds;
    }
    function bytesToSize(bytes) {
        if (bytes === 0) return '0 B';

        var k = 1024;

        sizes = ['B','KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

        i = Math.floor(Math.log(bytes) / Math.log(k));

        return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
    }
    $("#toUpload").bind("click",function () {
        window.location.href="/main";
    });
</script>
</body>
</html>

